<?php
/**
 * Created by PhpStorm.
 * User: 雨寒
 * Date: 2018/8/18
 * Time: 上午8:04
 */

namespace app\api\module;

use app\common\model\DeveloperException;
use app\common\model\User;
use app\common\model\Club;
use app\common\model\SMS;
use app\common\model\Order;
use app\common\model\Message;
use app\common\model\Consortium;
use app\common\model\UserException;
use app\common\model\Pay;

class Member extends Common
{
    /**
     * 判断是否需要登录
     *
     * @param string $interface 待检测的接口
     * @return bool
     */
    protected function needLogin($interface)
    {
        //不需登录的接口
        $ignoreList = [
            H_MEMBER_REGISTER,                   //注册
            H_MEMBER_LOGIN,                      //登录
            H_MEMBER_FORGET_PASSWORD             //忘记密码
        ];

        if (in_array($interface, $ignoreList))
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    /**
     * 执行接口操作
     *
     * @param $interface
     * @return string
     */
    public function exec($interface)
    {
        switch ($interface)
        {
            /**
             * @api {post} / 【1001】注册新用户
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_register
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} real_name 昵称
             * @apiParam (dataGroup) {String} mobile 手机号
             * @apiParam (dataGroup) {String} captcha 短信验证码
             * @apiParam (dataGroup) {String} password 密码（md5加密后）
             * @apiParam (dataGroup) {String} confirmpassword 确认密码（md5加密后）
             * @apiParam (dataGroup) {String} second_password 二级密码（md5加密后）
             * @apiParam (dataGroup) {String} second_confirmpassword 确认密码（md5加密后）
             *
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1001",
             *   "data": {
             *     "real_name": "雨寒",
             *     "mobile": "13355064521",
             *     "captcha": "123456",
             *     "password": "sdfasdfas",
             *     "confirmpassword": "sdfasdfas",
             *     "second_password": "sdfasdfas",
             *     "second_confirmpassword": "sdfasdfas"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccess (result_data-回执报文信息) {String} userid 用户唯一ID
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_data": {
             *      "userid": "123456"
             *   },
             *   "result_code": "0000",
             *   "result_info": "新用户注册成功！"
             * }
             *
             */
            case H_MEMBER_REGISTER:
                return $this->register();
            /**
             * @api {post} / 【1002】登录用户
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_login
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} mobile 手机号
             * @apiParam (dataGroup) {String} password 密码（md5加密后，全小写）
             * @apiParam (dataGroup) {String} captcha 验证码
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1002",
             *   "data": {
             *     "mobile": "13355064521",
             *     "captcha": "123456",
             *     "password": "6a204bd89f3c8348afd5c77c717a097a"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccess (result_data-回执报文信息) {String} access_token Access Token
             * @apiSuccess (result_data-回执报文信息) {String} userid 用户唯一ID
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_data": {
             *     "access_token": "l+ODeJqDuqErlzpGcecDYSHRhsChsSzUnbqp3mXH/uFR7SFwsSs6btHnmzWLdjq1F3n4OagyJaMErOwFKcRBN/6+wSlN+k6KravEH4KUunyOTKqhBXPayy+NZfHNyf3zwZhoFKz7nzu/I7Y8bd+MUeJ1vrzWxMf6Ih82JpsNNoDzXBk4fN5504ZICcHV8QAAxkdXDI18rQiWtlTWEr7yByy9yQOF381s/r0yphp3Orqo9Lmjmq0DbmHSn5grtzVG+6KYsHwYur7XOm+eqASCBA==",
             *     "userid": "123456"
             *   },
             *   "result_code": "0000",
             *   "result_info": "登录成功！"
             * }
             *
             */
            case H_MEMBER_LOGIN:
                return $this->login();
            /**
             * @api {post} / 【1003】首页
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_home
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token Access Token
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1003",
             *   "data": {
             *     "access_token": "cXzAvJgwCZJKVc8Ja/53Y16w2GlceoeBSPp3M39lt8gfhHJetDkDQ9uJe0l5XwZMRaYVsVdM3vqYjjFWe4nqlluJb7FeTydRTb/7ZimapIu97yu/IJ8F3BoFpaeHfduU"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_code": "0000",
             *   "result_info": "首页",
             *   "result_data": {
             *     "money":"1000",
             *     "h_ratio":"1.5",
             *     "date_arr": [
             *       {
             *        "2018-08-11"
             *       },
             *       {
             *        "2018-08-12"
             *       }
             *     ],
             *     "value_arr": [
             *       {
             *        "10"
             *       },
             *       {
             *        "12.5"
             *       }
             *     ],
             *     "notice_list": [
             *       {
             *         "id": "12",
             *         "title": "标题"
             *       },
             *       {
             *         "id": "13",
             *         "title": "标题"
             *       }
             *     ],
             *     "news_list":[
             *         {
             *             "id":"1",
             *             "title":"新闻标题",
             *             "content":"xinwenneiroing",
             *             "image":"https://www.baidu.com",
             *             "view_num":"1001",
             *             "tag_id":"2"
             *         },
             *        {
             *             "id":"2",
             *             "title":"新闻标题",
             *             "content":"xinwenneiroing",
             *             "image":"https://www.baidu.com",
             *             "view_num":"1001",
             *             "tag_id":"2"
             *         }
             *     ],
             *     "active_list":[
             *         {
             *             "id":"1",
             *             "title":"新闻标题",
             *             "time":"120520121",
             *             "image":"https://www.baidu.com",
             *             "address":"迪拜"
             *         },
             *        {
             *             "id":"10",
             *             "title":"新闻标题",
             *             "time":"120520121",
             *             "image":"https://www.baidu.com",
             *             "address":"迪拜"
             *         }
             *     ],
             *     "banner_list":[
             *         {
             *             "id":"1",
             *             "title":"轮播图标题",
             *             "image":"https://www.baidu.com",
             *             "url":""
             *         },
             *        {
             *             "id":"1",
             *             "title":"轮播图标题",
             *             "image":"https://www.baidu.com",
             *             "url":""
             *         }
             *     ],
             *     "bussiness_list":[
             *         {
             *             "id":"1",
             *             "avatar":"dfdfdf",
             *             "title":"商会名称",
             *             "member":[
             *                         {
             *                             "avatar":"dljfdljfdl",
             *                             "id":"12"
             *                          },
             *                          {
             *                             "avatar":"dljfdljfdl",
             *                             "id":"12"
             *                          }
             *                      ]
             *         },
             *         {
             *             "id":"2",
             *             "avatar":"dfjhdjf",
             *             "title":"商会名称",
             *             "member":[
             *                         {
             *                             "avatar":"dljfdljfdl",
             *                             "id":"12"
             *                          },
             *                          {
             *                             "avatar":"dljfdljfdl",
             *                             "id":"12"
             *                          }
             *                      ]
             *         }
             *     ],
             *     "consortium_list":[
             *         {
             *             "id":"1",
             *             "title":"轮播图标题",
             *             "thumb":"https://www.baidu.com",
             *             "tel":"1212121",
             *             "address":""
             *         },
             *        {
             *             "id":"1",
             *             "title":"轮播图标题",
             *             "thumb":"https://www.baidu.com",
             *             "tel":"1212121",
             *             "address":""
             *         }
             *     ],
             *    }
             * }
             */
            case H_MEMBER_HOME:
                return $this->home();
            /**
             * @api {post} / 【1004】忘记密码
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_forget_password
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} mobile 手机号
             * @apiParam (dataGroup) {String} captcha 短信验证码
             * @apiParam (dataGroup) {String} newpassword 新密码
             * @apiParam (dataGroup) {String} confirmpassword 确认密码
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1004",
             *   "data": {
             *     "mobile": "13355064521",
             *     "captcha": "123456",
             *     "newpassword": "6a204bd89f3c8348afd5c77c717a097a",
             *     "confirmpassword": "6a204bd89f3c8348afd5c77c717a097a"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_code": "0000",
             *   "result_info": "找回密码成功！"
             * }
             *
             */
            case H_MEMBER_FORGET_PASSWORD:
                return $this->forgetPassword();

            /**
             * @api {post} / 【1005】修改密码
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_change_password
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token Access Token
             * @apiParam (dataGroup) {String} oldpassword 密码
             * @apiParam (dataGroup) {String} newpassword 新密码
             * @apiParam (dataGroup) {String} confirmpassword 确认密码
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1005",
             *   "data": {
             *     "access_token":"token",
             *     "oldpassword": "6a204bd89f3c8348afd5c77c717a097a",
             *     "newpassword": "6a204bd89f3c8348afd5c77c717a097a",
             *     "confirmpassword": "6a204bd89f3c8348afd5c77c717a097a",
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_code": "0000",
             *   "result_info": "修改密码成功！"
             * }
             *
             */
            case H_MEMBER_CHANGE_PASSWORD:
                return $this->changePassword();
            /**
             * @api {post} / 【1006】显示设置
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_set
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token Access Token
             *
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1006",
             *   "data": {
             *     "access_token": "l+ODeJqDuqErlzpGcecDYSHRhsChsSzUnbqp3mXH/uFR7SFwsSs6btHnmzWLdjq1F3n4OagyJaMErOwFKcRBN/6+wSlN+k6KravEH4KUunyOTKqhBXPayy+NZfHNyf3zLQ2SWl+21aqZhD6/yu8qM/cG4K1Vg1ebESXfEF8z93JD4cn28Ks1UsHmm62JPUcz"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             *
             * @apiSuccess (result_data-回执报文信息) {String} userid 用户唯一ID
             * @apiSuccess (result_data-回执报文信息) {String} real_name 姓名
             * @apiSuccess (result_data-回执报文信息) {String} email 邮箱
             * @apiSuccess (result_data-回执报文信息) {String} abstract  简介
             * @apiSuccess (result_data-回执报文信息) {String} mobile 用户手机号
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_data": {
             *     "userid": "123456",
             *     "real_name": "雨寒",
             *     "email": "jdkdjlkf@163.com",
             *     "abstract": "我的简介",
             *     "mobile": "18854485466"
             *   },
             *   "result_code": "0000",
             *   "result_info": "进入设置"
             * }
             *
             */
            case H_MEMBER_SET:
                return $this->set();
            /**
             * @api {post} / 【1007】修改设置
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_set_update
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token Access Token
             * @apiParam (dataGroup) {String} type 修改的type（1：姓名，2：邮箱，3：简介,4:服务项目）
             * @apiParam (dataGroup) {String} content 修改后的内容
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1007",
             *   "data": {
             *     "access_token": "l+ODeJqDuqErlzpGcecDYSHRhsChsSzUnbqp3mXH/uFR7SFwsSs6btHnmzWLdjq1F3n4OagyJaMErOwFKcRBN/6+wSlN+k6KravEH4KUunyOTKqhBXPayy+NZfHNyf3zLQ2SWl+21aqZhD6/yu8qM/cG4K1Vg1ebESXfEF8z93JD4cn28Ks1UsHmm62JPUcz",
             *      "type": "1",
             *      "content": "我的姓名"
             *
             *    }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_code": "0000",
             *   "result_info": "修改成功！"
             * }
             *
             */
            case H_MEMBER_SET_UPDATE:
                return $this->set_update();
            /**
             * @api {post} / 【1008】修改头像
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_modify_avatar
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token Access Token
             * @apiParam (dataGroup) {String} avatar_url 头像地址
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1008",
             *   "data": {
             *     "access_token": "l+ODeJqDuqErlzpGcecDYSHRhsChsSzUnbqp3mXH/uFR7SFwsSs6btHnmzWLdjq1F3n4OagyJaMErOwFKcRBN/6+wSlN+k6KravEH4KUunyOTKqhBXPayy+NZfHNyf3zLQ2SWl+21aqZhD6/yu8qM/cG4K1Vg1ebESXfEF8z93JD4cn28Ks1UsHmm62JPUcz",
             *     "avatar_url":"1"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_code": "0000",
             *   "result_info": "修改头像成功！"
             * }
             *
             */
            case H_MEMBER_MODIFY_AVATAR:
                return $this->modifyAvatar();
            /**
             * @api {post} / 【1009】修改手机号
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_change_mobile
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token    token
             * @apiParam (dataGroup) {String} captcha 验证码
             * @apiParam (dataGroup) {String} newmobile 新手机号
             *
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1009",
             *   "data": {
             *     "access_token":"token",
             *     "newmobile": "13355064521",
             *     "captcha": "6a204bd89f3c8348afd5c77c717a097a"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_code": "0000",
             *   "result_info": "修改手机成功！"
             * }
             *
             */
            case H_MEMBER_CHANGE_MOBILE:
                return $this->change_mobile();
            /**
             * @api {post} / 【1010】更多新闻
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_news
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token Access Token
             * @apiParam (dataGroup) {String} page 第几页
             * @apiParam (dataGroup) {String} page_size 每页几个
             * @apiParam (dataGroup) {String} bussiness_id 商会id(可以为空，为空时为平台新闻)
             *
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1010",
             *   "data": {
             *     "access_token": "l+ODeJqDuqErlzpGcecDYSHRhsChsSzUnbqp3mXH/uFR7SFwsSs6btHnmzWLdjq1F3n4OagyJaMErOwFKcRBN/6+wSlN+k6KravEH4KUunyOTKqhBXPayy+NZfHNyf3zLQ2SWl+21aqZhD6/yu8qM/cG4K1Vg1ebESXfEF8z93JD4cn28Ks1UsHmm62JPUcz",
             *     "page":"1",
             *     "bussiness_id":"1",
             *     "page_size":"10"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccess (result_data-回执报文信息) {Array} news_list 新闻列表
             *
             * @apiSuccess (news_list-消息列表) {String} title 消息标题
             * @apiSuccess (news_list-消息列表) {String} content 消息内容
             * @apiSuccess (news_list-消息列表) {String} image 图片
             * @apiSuccess (news_list-消息列表) {String} id 新闻id
             * @apiSuccess (news_list-消息列表) {String} view_num 查看数量
             * @apiSuccess (news_list-消息列表) {String} tag_id 标签
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_data": {
             *     "news_list": [
             *       {
             *         "id":"1",
             *             "title":"新闻标题",
             *             "content":"xinwenneiroing",
             *             "image":"https://www.baidu.com",
             *             "view_num":"1001",
             *             "tag_id":"2"
             *       },
             *       {
             *         "id":"1",
             *             "title":"新闻标题",
             *             "content":"xinwenneiroing",
             *             "image":"https://www.baidu.com",
             *             "view_num":"1001",
             *             "tag_id":"2"
             *       }
             *     ]
             *   },
             *   "result_code": "0000",
             *   "result_info": "获取新闻列表成功！"
             * }
             *
             */
            case H_MEMBER_NEWS_LIST:
                return $this->news_list();

            /**
             * @api {post} / 【1011】新闻详情
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_news_info
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token Access Token
             * @apiParam (dataGroup) {String} news_id 消息id
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1011",
             *   "data": {
             *     "access_token": "l+ODeJqDuqErlzpGcecDYSHRhsChsSzUnbqp3mXH/uFR7SFwsSs6btHnmzWLdjq1F3n4OagyJaMErOwFKcRBN/6+wSlN+k6KravEH4KUunyOTKqhBXPayy+NZfHNyf3zLQ2SWl+21aqZhD6/yu8qM/cG4K1Vg1ebESXfEF8z93JD4cn28Ks1UsHmm62JPUcz",
             *     "news_id": "10",
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccess (result_data-回执报文信息) {String} title biaoti
             * @apiSuccess (result_data-回执报文信息) {String} update_time 时间
             * @apiSuccess (result_data-回执报文信息) {String} detail 内容详情
             * @apiSuccess (result_data-回执报文信息) {String} thumb tupian
             * @apiSuccess (result_data-回执报文信息) {String} view_num 浏览人数
             * @apiSuccess (result_data-回执报文信息) {String} category_id 标签
             *
             *
             *

             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_data": {
             *             "title":"新闻标题",
             *             "detail":"xinwenneiroing",
             *             "thumb":"https://www.baidu.com",
             *             "update_time":"545121805451",
             *             "view_num":"1001",
             *             "category_id":"2"
             *   },
             *   "result_code": "0000",
             *   "result_info": "获得新闻详情成功！"
             * }
             *
             */
            case H_MEMBER_NEWS_INFO:
                return $this->news_info();
            /**
             * @api {post} / 【1012】我的人脉（暂不用）
             * @apiDescription <label class="label label-success" style="font-size: 18px;">暂不用</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_my_connection
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token token
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1012",
             *   "data": {
             *     "access_token": "6a204bd89f3c8348afd5c77c717a097a"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccess (result_data-回执报文信息) {Array} member_list 会员列表
             * @apiSuccess (member_list-回执报文信息) {String} avatar 会员头像
             * @apiSuccess (member_list-回执报文信息) {String} name 姓名
             * @apiSuccess (member_list-回执报文信息) {String} position 哪个部门
             * @apiSuccess (member_list-回执报文信息) {String} mobile 手机号
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_data": {
             *     "member_list":[
             *         {
             *                 "avatar":"http://12121",
             *                 "name":"yuhan",
             *                 "position":"技术部",
             *                 "mobile":"18853926512",
             *         },
             *         {
             *                 "avatar":"http://12121",
             *                 "name":"yuhan",
             *                 "position":"会长",
             *                 "mobile":"1888555451",
             *         },
             *      ]
             *   },
             *   "result_code": "0000",
             *   "result_info": "会员列表！"
             * }
             *
             */
            case H_MEMBER_LIST:
                return $this->member_list();
            /**
             * @api {post} / 【1013】提交建议
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_suggest
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token    token
             * @apiParam (dataGroup) {String} content    建议内容
             *
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1013",
             *   "data": {
             *     "access_token":"token"，
             *     "content":"建议内容"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_code": "0000",
             *   "result_info": "提交成功！"
             * }
             *
             */
            case H_MEMBER_SUGGEST:
                return $this->member_suggest();
            /**
             * @api {post} / 【1014】激活
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_activity
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token    token
             * @apiParam (dataGroup) {String} activate_fee    激活的费用
             * @apiParam (dataGroup) {String} pay_type    支付方式
             *
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1014",
             *   "data": {
             *     "access_token":"token",
             *     "activate_fee":"100",
             *     "pay_type":"1"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_code": "0000",
             *   "result_info": "激活！"
             * }
             *
             */
            case H_MEMBER_ACTIVITY:
                return $this->member_activity();
            /**
             * @api {post} / 【1015】影响力（我的推荐）
             * @apiDescription <label class="label label-success" style="font-size: 18px;">已实现</label>
             *
             * @apiVersion 1.0.0
             * @apiName member_effect_list
             * @apiGroup 用户【Member】
             *
             * @apiUse tnCommonParamTN
             *
             * @apiParam (dataGroup) {String} access_token token
             * @apiParam (dataGroup) {String} page 第几页
             * @apiParam (dataGroup) {String} page_size 每页几个
             *
             * @apiParamExample {json} 请求参数示例
             *
             * {
             *   "version": "1.0.0",
             *   "module": "Member",
             *   "interface": "1015",
             *   "data": {
             *     "access_token": "6a204bd89f3c8348afd5c77c717a097a",
             *     "page":"1",
             *     "page_size":"10"
             *   }
             * }
             *
             * @apiSuccess (基础报文信息) {String} result_code 结果编码.
             * @apiSuccess (基础报文信息) {String} result_info  结果信息.
             * @apiSuccess (基础报文信息) {Object} result_data  回执报文数据.
             *
             * @apiSuccess (result_data-回执报文信息) {Array} member_list 会员列表
             * @apiSuccess (member_list-回执报文信息) {String} id 会员ID
             * @apiSuccess (member_list-回执报文信息) {String} avatar 会员头像
             * @apiSuccess (member_list-回执报文信息) {String} name 姓名
             * @apiSuccess (member_list-回执报文信息) {String} position 哪个部门
             * @apiSuccess (member_list-回执报文信息) {String} mobile 手机号
             *
             * @apiSuccessExample 成功示例
             * {
             *   "result_data": {
             *     "member_list":[
             *         {
             *                 "id":"2",
             *                 "avatar":"http://12121",
             *                 "name":"yuhan",
             *                 "position":"技术部",
             *                 "mobile":"18853926512",
             *         },
             *         {
             *                 "id":"2",
             *                 "avatar":"http://12121",
             *                 "name":"yuhan",
             *                 "position":"会长",
             *                 "mobile":"1888555451",
             *         },
             *      ]
             *   },
             *   "result_code": "0000",
             *   "result_info": "会员列表！"
             * }
             *
             */
            case H_MEMBER_EFFECT_LIST:
                return $this->member_effect_list();
            default:
                send_developer_error("模块【用户】中不存在接口【" . $interface . "】,核实文档后重试!");
        }
    }

    /**
     * 注册新用户
     *
     * @return array
     */
    private function register()
    {
        /*姓名*/
        $real_name=$this->essentialParam("real_name");

        //手机号
        $mobile = $this->essentialParam("mobile");
        //短信验证码
        $captcha = $this->essentialParam("captcha");

        //验证验证码
        SMS::verifyCaptcha($mobile, $captcha);

        //密码
        $password = $this->essentialParam("password");
        /*确认密码*/
        $confirmpassword = $this->essentialParam("confirmpassword");

        //二级密码
//        $second_password = $this->essentialParam("second_password");
        /*确认密码*/
//        $second_confirmpassword = $this->essentialParam("second_confirmpassword");
        //手机号
        $parent_mobile = $this->optionalParam("parent_mobile");
        //行业
        $duties_id = $this->optionalParam("duties_id");
        //职位
        $industry_id = $this->optionalParam("industry_id");
        //服务项目
        $server = $this->optionalParam("server");
        //自我简介
        $abstract = $this->optionalParam("abstract");
        //商会id
        $bussiness_id= $this->optionalParam("bussiness_id");
        /*开始注册*/
        $userid=User::register($real_name,$mobile,$password,$confirmpassword,$parent_mobile,$duties_id,$industry_id,$server,$abstract,$bussiness_id);

        //注册用户
        $this->insertResponse("userid", $userid);

        return $this->response("新用户注册成功！");
    }

    /*
     * 用户登录
     */
    private function login()
    {
        //手机号
        $mobile = $this->essentialParam("mobile");
        //密码
        $password = $this->optionalParam("password");
        //验证码
        $captcha = $this->optionalParam("captcha");

        //登录后获取用户信息
        $info = User::login($mobile, $password,$captcha);

        $this->insertResponse("access_token", $info['token']);

        //用户ID
        $this->insertResponse("userid", $info['uid']);
        $this->insertResponse("bussiness_id", $info['bussiness_id']);

        return $this->response("登录成功！");
    }

    /*首页*/
    /**
     * @return array
     * @throws DeveloperException
     * @throws UserException
     * @throws \app\common\model\TokenException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    private function home()
    {
        /*获取token*/
        $access_token = $this->essentialParam("access_token");

        /*验证token，获取用户信息*/
        $userinfo=User::userFromToken($access_token);

        /*获取商会信息*/
        $bussiness_info=Club::bussinessInfoById($userinfo['bussiness_id']);
        if(empty($bussiness_info))
        {
            $bussiness_info['city']=182;
        }

        /*最近七天的价格*/
        $time=time();
        $data=array(
            "time"=>$time,
            "token"=>md5(md5(substr($time,3)))
        );
        $url=config('post_url')."/commerce/setChart";
        $res=curl_post($url,json_encode($data));
        $date_arr=json_decode($res,true)['result'];

        //最近七天的时间
//        $date_arr= json_encode(
//            array(
//                array("year"=>date("m-d",strtotime("-6 day")),"value"=>10),
//                array("year"=>date("m-d",strtotime("-5 day")),"value"=>12),
//                array("year"=>date("m-d",strtotime("-4 day")),"value"=>14),
//                array("year"=>date("m-d",strtotime("-3 day")),"value"=>8),
//                array("year"=>date("m-d",strtotime("-2 day")),"value"=>11),
//                array("year"=>date("m-d",strtotime("-1 day")),"value"=>15),
//                array("year"=>"今天","value"=>20),
//            )
//        );

        $value_arr=["m"=>10,20,30];
        /*公告列表*/
        $arr1=Message::noticeList($userinfo['bussiness_id'],1,1);
        $arr2=Message::noticeList(0,1,1);

        $notice_list=[];
        if(!empty($arr1))
        {
            array_push($notice_list,$arr1[0]);
        }
        if(!empty($arr2))
        {
            array_push($notice_list,$arr2[0]);
        }
        /*新闻列表*/
        $news_list=Message::newsList(0,$bussiness_info['city'],1,3);
        /*活动列表*/
        $active_list=Message::activityList(1,$bussiness_info['city'],1,2);
        /*轮播图*/
        $banner_list=Message::bannerList(1,$bussiness_info['city']);
        /*商会列表*/
        $bussiness_list=Club::bussinessList(1,1,3,$userinfo);
        /*联盟商列表*/
        $consortium_list=Consortium::consortiumList(0,$bussiness_info['city'],1,3);

        $this->insertResponse('date_arr',$date_arr);
        $this->insertResponse('value_arr',$value_arr);
        $this->insertResponse('notice_list',$notice_list);
        $this->insertResponse('news_list',$news_list);
        $this->insertResponse('active_list',$active_list);
        $this->insertResponse('banner_list',$banner_list);
        $this->insertResponse('bussiness_list',$bussiness_list);
        $this->insertResponse('consortium_list',$consortium_list);



        return $this->response("首页！");
    }

    /**
     * 忘记密码
     *
     * @return array
     */
    private function forgetPassword()
    {
        //手机号
        $mobile = $this->essentialParam("mobile");
        //短信验证码
        $captcha = $this->essentialParam("captcha");

        //验证验证码
        SMS::verifyCaptcha($mobile, $captcha);

        //新密码
        $newpassword = $this->essentialParam("newpassword");
        $confirmpassword = $this->essentialParam("confirmpassword");

        /*处理密码*/
        User::forgetPassword($mobile,$newpassword,$confirmpassword);
        return $this->response("新密码设置成功！");
    }

    //修改密码
    private function changePassword()
    {
        //token
        $access_token = $this->essentialParam("access_token");
        /*验证token，获取用户信息*/
        $userinfo=User::userFromToken($access_token);

        //旧密码
        $oldpassword = $this->essentialParam("oldpassword");
        //新密码
        $newpassword = $this->essentialParam("newpassword");
        
        //确认密码
        $confirmpassword = $this->essentialParam("confirmpassword");

        //更改密码
        User::changePassword($userinfo, $oldpassword,$newpassword,$confirmpassword);

        return $this->response("修改密码成功！");
    }

    //修改手机
    private function change_mobile()
    {
        //token
        $access_token = $this->essentialParam("access_token");
        /*验证token，获取用户信息*/
        $userinfo=User::userFromToken($access_token);
        //新手机号
        $newmobile = $this->essentialParam("newmobile");
        /*验证码*/
        $captcha = $this->essentialParam("captcha");
        /*验证*/
        SMS::verifyCaptcha($userinfo['mobile'], $captcha);
        /*修改*/
        User::modifyMobile($userinfo, $newmobile);

        return $this->response("修改密码成功！");
    }
    /*显示设置*/
    private function set()
    {
        //token
        $access_token=$this->essentialParam('access_token');
        /*验证token，获取用户信息*/
        $userinfo=User::userFromToken($access_token);
        //用户手机号
        $this->insertResponse('mobile',$userinfo['mobile']);
        //用户姓名
        $this->insertResponse('real_name',$userinfo['real_name']);
        //邮箱
        $this->insertResponse('email',$userinfo['email']);
        /*商会*/
        if($userinfo['bussiness_id'])
        {
            $bussiness= Club::bussinessInfoById($userinfo['bussiness_id']);
            $this->insertResponse('bussiness_name',$bussiness['title']);
        }
        /*职务*/
        if($userinfo['duties_id'])
        {
            $duties= Club::dutiesInfoById($userinfo['duties_id']);
            $this->insertResponse('duties_name',$duties['title']);
        }
        /*部门*/
        if($userinfo['department_id'])
        {
            $department= Club::departmentInfoById($userinfo['department_id']);
            $this->insertResponse('department_name',$department['title']);
        }

        return $this->response('会员设置！');
    }

    //修改设置
    private function set_update()
    {
        /*access_token*/
        $access_token=$this->essentialParam('access_token');
        /*用户信息*/
        $user=User::userFromToken($access_token);
        //修改的类型
        $type=$this->essentialParam('type');
        //修改后的内容
        $content=$this->essentialParam('content');

        User::setUpdate($user,$type,htmlspecialchars($content));

        return $this->response("修改成功！");
    }

    //修改头像
    private function modifyAvatar()
    {

        $access_token=$this->essentialParam('access_token');
        /*检验token获取用户信息*/
        $user=User::userFromToken($access_token);
        /*要更改的头像id*/
        $avatar_url=$this->essentialParam('avatar_url');
        User::modifyAvatar($user,$avatar_url);
        return $this->response("修改头像成功！");
    }


    //新闻列表
    private function news_list()
    {
        $access_token=$this->essentialParam('access_token');
        $category_id=$this->optionalParam('category_id');
        $bussiness_id=$this->essentialParam('bussiness_id');
        $page=$this->essentialParam('page');
        $page_size=$this->essentialParam('page_size');
        /*验证token及获取用户信息*/
        $user=User::userFromToken($access_token);

        /*获取商会信息*/
        $bussiness_info=Club::bussinessInfoById($user['bussiness_id']);
        if(empty($bussiness_info))
        {
            $bussiness_info['city']=182;
        }

        $message_list=Message::newsList($bussiness_id, $bussiness_info['city'],$page,$page_size,$category_id);
        $this->insertResponse("list", $message_list);

        return $this->response("获取新闻列表成功！");
    }


    //信息详情
    private function news_info()
    {
        $access_token=$this->essentialParam('access_token');
        /*信息id*/
        $news_id=$this->essentialParam('news_id');

        $messageinfo=Message::newsInfo($news_id);

        $this->insertResponse("title", $messageinfo['title']);
        $this->insertResponse("update_time", $messageinfo['update_time']);
        $this->insertResponse("detail", $messageinfo['detail']);
        $this->insertResponse("description", $messageinfo['description']);
        $this->insertResponse("thumb", $messageinfo['thumb']);
        $this->insertResponse("view_num", $messageinfo['view_num']);
        $this->insertResponse("category_id", $messageinfo['category_id']);
        $this->insertResponse("city", $messageinfo['city']);

        return $this->response("获取消息详情成功！");
    }

    //意见反馈
    private function member_suggest()
    {
        $access_token=$this->essentialParam('access_token');
        $content=$this->essentialParam('content');
        /*检验token获取用户信息*/
        $user=User::userFromToken($access_token);

        User::memberSuggest($user,htmlspecialchars($content));
        return $this->response("建议已提交！");
    }

/*激活会员*/
    private function member_activity()
    {
        $access_token=$this->essentialParam('access_token');
        $pay_type=$this->essentialParam('pay_type');
        $activate_fee=$this->essentialParam('activate_fee');
        /*检验token获取用户信息*/
        $user=User::userFromToken($access_token);

        /*判断是否开通钱包*/
        $time=time();
        $data=array(
            'mobile' =>$user['mobile'],
            "time"=>$time,
            "token"=>md5(md5(substr($time,3)))
        );
        $url=config('post_url')."/commerce/usertrue";
        $res=curl_post($url,json_encode($data));
        $res=json_decode($res,true);
        if($res['error_code']==1)
        {
            throw new DeveloperException("您还没有开启钱包，请去‘钱包’并设置支付密码！");
        }

        /*生成订单*/
        $order=Order::establish($user,$activate_fee,0,1,0,0,$pay_type,0,$activate_fee);
        $body="会员激活";
        /*支付类型*/
        if($pay_type==1)
        {
            /*微信支付统一下单*/
            $payInfo=Pay::weixinPay($order['orderid'],$order['money'],$body);

        }else{

            /*支付宝支付统一下单*/
            $payInfo=Pay::aliPay($order['orderid'],$order['money'],$body);
        }

        $this->insertResponse('pay_info',$payInfo);
        $this->insertResponse('order_sn',$order['orderid']);
        return $this->response("会员已激活！");
    }

    //影响力中心列表
    private function member_effect_list()
    {
        $access_token=$this->essentialParam('access_token');

        $page=$this->essentialParam('page');
        $page_size=$this->essentialParam('page_size');
        /*验证token及获取用户信息*/
        $user=User::userFromToken($access_token);

        $message_list=Club::effectList($user,$page,$page_size);
        $this->insertResponse("list", $message_list);

        return $this->response("影响力人列表！");
    }


}